<!DOCTYPE html>
<html>
<head lang="zh-CN">
    <meta charset="UTF-8">
    <meta name="viewport" content=" initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <title>我的店铺</title>
    <link href="{$Think.config.RESOURCEURL}wx_assets/css/common.css{$Think.config.RESOURCE_VER}" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="{$Think.config.RESOURCEURL}wx_assets/quan/showIndex.css{$Think.config.RESOURCE_VER}" />
    <script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.1.1.3.min.js{$Think.config.RESOURCE_VER}"></script>
    <script src="{$Think.config.RESOURCEURL}wx_assets/js/util.js{$Think.config.RESOURCE_VER}" type="text/javascript"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/wx_share.js{$Think.config.RESOURCE_VER}"></script>
</head>
<body>
<div class="container">
    <div class="pInformation <if condition="$themeImgUrl eq '' ">defaultTheme</if>" <if condition="$themeImgUrl neq '' "> style="background-image:url({$themeImgUrl})"</if>>
    <div class="information">
        <div class="portrait">
        <if condition="$isShare eq '1'">
                <a ><img src="{$headImgUrl}" onload="$.util.imgCenter(this)" /></a>
            <else/>
            <a href='{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&module=quan&method=home&params=%7B"qId"%3A"{$qId}"%7D'><img src="{$headImgUrl}" onload="$.util.imgCenter(this)"/></a>
          </if>
        </div>
        <div class="fullname">
            <div style="font-size:15px;">{$nickName}</div>
            <div style="font-size:13px;">{$wxId}</div>
        </div>
        <div class="wxbz">
            <if condition="$wxId neq ''">
                <span></span>
            </if>
            <label>{$wxId}</label>
            <br/>
            {$slogan}
        </div>
    </div>
</div>
<div class="menu"><span>我的推荐</span></div>
    <div class="product" id="proBox"></div>
</div>
</body>
<script type="text/html" id="shopTpl">
    <%if(proList){
    var cnt=0;
    var len =proList.length;
    for(var i=0;i<len;i++){
        var item=proList[i];
    %>
    <div class="list">
    <div class="productList" align="center"  onclick="shop.toDetail('<%=item.fromCustomerId%>','<%=item.pId%>')">
        <%if(item.isAdd) {%>
        <div class="disc">喜欢</div>
        <%}%>
            <div class="imgbox"><img src="<%=item.picUrl%>@250h_1sh" onload="$.util.imgZoom(this,'100%')" title="<%=item.name%>"/></div>
            <div class="name"><%=item.name%></div>
            <div class="price">￥<% if(item.discountedPrice) {%>
                    <%=item.discountedPrice%>
                <%} else {%>
                    <%=item.fixedPrice%>
                <%}%>
            元</div>
    </div>
    </div>
    <%}%>
    <%} else {%>
    <div class="norecord">没有相关商品</div>
    <%}%>
</script>
<script type="text/javascript">
    var baseUrl = '{$Think.config.SERVER_HOST}';
    var shop={
        pageSize:10,
        page:0,
        guid:"{$guid}",
        init:function(){
            var me=this;
            $.util.pageLoading.show();
            me._loadList(me.page,function(){
                $.util.pageLoading.hide();
            });
            this._initEvent();
        },
        _initMask:function(){
            if(!$.util.cookie("shopMask")){
                $("#tipMask").height($.util.page.getHeight()).show();
                $("#tipMask .button").click(function(e){
                    $("#tipMask").hide();
                    e.stopPropagation();
                });
                $.util.cookie("shopMask",1,{'path':'/',"expires":365});
            }
        },
        toDetail:function(customerId,id){
            var p=$.util.getParamAsObject();
            var params={
                "id":id,
                "miUId":"{$fromUId}",
                "qId":p.qId,
                "fromGuid":p.fromGuid
            }
            params=encodeURIComponent(JSON.stringify(params));
            location.href= 'call.html?customerId='+customerId+'&module=product&method=getProduct&params='+params;
        },
        _initEvent:function(){
            var me=this;
            $.util.initDataLoading({
                me:shop,
                lastChildren:function(){
                    return $("#proBox .list:last");
                },
                page:function(){
                    return shop.page;
                },
                pageCount:function(){
                    return shop.pageCount;
                }
            });
        },
        _renderList:function(data,page,callback){
            var me=this;
            if(data){
                var html=template("shopTpl", data),
                        container=$("#proBox");
                container.append(html);
                me.page=page;
                me.pageCount=data.pageCount;
                callback && callback();
            }
        },
        _loadList:function(page,callback){
            var me=this;
            $.req.get("call.json?module=quan&customerId={$customerId}&method=getShopPro",{
                userName:"{$userName}",
                params:{
                    "qId":"{$qId}",
                    "start":page,
                    "limit":me.pageSize,
                    "fromUId":"{$fromUId}"
                }
            },function(data){
                if(data){
                    me._renderList(data,page,callback);
                }
            });
        },
        share:function(){
            var fromGuid=$.util.getParamByObject("fromGuid") || "";
            $.req.get("call.json?customerId={$customerId}&module=quan&method=saveShare&userName={$userName}",{
                params:{
                    "qId":"{$qId}",
                    "sId":"{$sId}",
                    "guid":"{$guid}",
                    "fromGuid":fromGuid,
                    "miUId":"{$fromUId}",
                    "shareType":1,
                    "fromPage":"shopIndex"
                }
            },function(data){
                if(data && !data.code){

                }
            });
        },
        getShareUrl:function(){
            var qId=$.util.getParamByObject("qId");
            var shareUrl="";
            var me=this;
            var params={
                "fromGuid":me.guid,
                "miUId":"{$fromUId}",
                "qId":"{$qId}",
                "fromUId":"{$fromUId}"
            };
            params=encodeURIComponent(JSON.stringify(params));
            shareUrl=baseUrl+'call.html?customerId={$customerId}&module=quan&scope=1&method=shopIndex&params='+params;
            return shareUrl;
        }
    }
    shop.init();
    var shareUrl=shop.getShareUrl();
    wx_share.init({
            "title":"{$nickName}的密友圈",
            "desc":'{$slogan}',
            "link":shareUrl,
            "imgUrl":"{$headImgUrl}",
            "pkg":{
                "appId": '{$pkg.appId}',
                "timestamp": {$pkg.timestamp},
                "nonceStr": '{$pkg.nonceStr}',
                "signature": '{$pkg.signature}'
            },
            success:function(config,shareType){
            var qId=$.util.getParamByObject("qId");
            var fromGuid=$.util.getParamByObject("fromGuid") || "";
            $.req.get("call.json?customerId={$customerId}&module=quan&method=saveShare&userName={$userName}",{
                params:{
                    "qId":qId,
                    "sId":"{$sId}",
                    "guid":shop.guid,
                    "fromGuid":fromGuid,
                    "miUId":"{$fromUId}",
                    "shareType":shareType,
                    "fromPage":"shopIndex"
                }
            },function(data){
                if(data && !data.code){
                    shop.guid=data.guid;
                }
            });
        }
    });
</script>
</html>